package com.futu.kafka;

import com.alibaba.fastjson.JSON;
import com.futu.attraction.config.TemperatureAlert;
import com.futu.common.utils.RedisUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

// 注释掉整个测试控制器，防止误用
/*
@RestController
@RequestMapping("/test")
public class TemperatureAlertTest {

    @Resource
    private RedisUtil redisUtil;

    @GetMapping("/createAlert")
    public String createTestAlert(@RequestParam(defaultValue = "杭州") String cityName) {
        try {
            // 创建一个测试温度告警
            TemperatureAlert alert = new TemperatureAlert(
                    cityName,
                    35.5,
                    new Date(),
                    "温度超过30°C，不建议外出游玩！"
            );

            // 将告警存入Redis
            String alertKey = "temperature_alert:" + cityName;
            String alertJson = JSON.toJSONString(alert);
            
            redisUtil.set(alertKey, alertJson, 86400); // 24小时
            
            // 打印所有temperature_alert开头的键，用于调试
            redisUtil.printAllKeys("temperature_alert:*");
            
            return "成功创建测试温度告警: " + alertJson;
        } catch (Exception e) {
            e.printStackTrace();
            return "创建测试温度告警失败: " + e.getMessage();
        }
    }
    
    @GetMapping("/getAlert")
    public String getTestAlert(@RequestParam(defaultValue = "杭州") String cityName) {
        try {
            // 从Redis获取温度告警
            String alertKey = "temperature_alert:" + cityName;
            String alertJson = redisUtil.get(alertKey);
            
            if (alertJson != null) {
                return "获取到温度告警: " + alertJson;
            } else {
                return "未找到城市" + cityName + "的温度告警";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "获取温度告警失败: " + e.getMessage();
        }
    }
    
    @GetMapping("/clearAlert")
    public String clearTestAlert(@RequestParam(defaultValue = "杭州") String cityName) {
        try {
            // 清除Redis中的温度告警
            String alertKey = "temperature_alert:" + cityName;
            redisUtil.delete(alertKey);
            
            return "已清除城市" + cityName + "的温度告警";
        } catch (Exception e) {
            e.printStackTrace();
            return "清除温度告警失败: " + e.getMessage();
        }
    }
}
*/

// 替换为空类，保持文件存在但不提供任何功能
public class TemperatureAlertTest {
    // 空类，不提供任何测试功能
} 